<?php

class Session {
    
    public static $lifetime = 0;
    public static $path = '/';
    public static $domain = '';
    public static $secure = false;    
    public static $httponly = true;
    
    private static $session_id;
    
    public static function setSessionName ($name) {
        session_name($name);
    }
    
    public static function start () {
        $session_id = $_COOKIE[session_name()];
        if (! $session_id) {
            session_id(self::genSessionId());
            self::setSessionCookie(self::$lifetime, self::$path, self::$domain, self::$secure, self::$httponly);
        }
        session_start();
    }
    
    public static function setHandlerDb () {
        
        session_set_save_handler(array(
            'SessionModel' ,'open'), 
            array(
            	'SessionModel' ,'close'),
            array(
            	'SessionModel' ,'read'),
            array(
            	'SessionModel' ,'write'),
            array(
            	'SessionModel' ,'destroy'),
            array(
            	'SessionModel' ,'gc'));
            
    }
    
    public static function setSessionCookie ($lifetime, $path = '/', $domain = '', $secure = false, $httponly = true) {
        session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
    }
    
    public static function regenerate () {
        SessionModel::regenerate();
    }
    
    public static function genSessionId () {
        return md5(uniqid(mt_rand(), true));
    }
    
    public static function getSessionId () {
        return session_id();
    }
    
}
?>